/**
 * This file will show when exception happen, to show the stack traced list
 */
package v1c11;

import java.util.Scanner;

/**
 * @author gjunming@gmail.com
 * @version Aug 11, 2009 2:16:58 PM
 */
public class StackTraceTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Enter number:");
		Integer number = input.nextInt();
		System.out.println("Result:" + factorial(number));
	}

	public static int factorial(int number) {
		System.out.println("factorial(" + number + "):");
		Throwable t = new Throwable();
		StackTraceElement[] stacks = t.getStackTrace();
		for (StackTraceElement stack : stacks) {
			System.out.println(stack);
		}
		int r;
		if(number < 1){
			r = 1;
		}
		else{
			r = number * factorial(number - 1);
		}
		return r;
	}

}